/*
 * @Description: User
 * @Author: zoeblow
 * @Email: wangfuyuan@nnuo.com
 * @Date: 2019-12-12 14:48:38
 * @LastEditors: zoeblow
 * @LastEditTime: 2019-12-12 16:07:29
 * @FilePath: \monitor-manage\schema\user.js
 */
const mongoose = require("../config/db");

/**
 * @description: 利用 mongoose.Schema
 */

const Schema = mongoose.Schema;

let user = {
  name: String,
  age: Number,
  tel: String
};

const userSchema = Schema(user);

userSchema.query.byName = function(name) {
  return this.find({ name: new RegExp(name, "i") });
};

const User = mongoose.model("User", userSchema);

module.exports = { User };
